package com.lzhl.buildjar.util;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageProducer;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 李柱良(@柱子的日月)
 * @date 2015/11/30
 */
public class ImageUtils {

    public static void main(String[] args) throws Exception {
        Color color = null;

        color = new Color(60, 179, 0);
//        buildLogo(color, "./src/image/logo2.png");
//        buildBrowser(17, 20, color, "./src/image/browser.png");
//        buildMoveDown(17, 20, color, "./src/image/movedown.png");
//        buildMoveBottom(17, 20, color, "./src/image/movebottom.png");
//        buildMoveUp(17, 20, color, "./src/image/moveup.png");
//        buildMoveTop(17, 20, color, "./src/image/movetop.png");
//        buildDelete(17, 20, color, "./src/image/delete.png");
//        buildAdd(17, 20, color, "./src/image/add.png");
//        buildLineLocation(17, 20, color, "./src/image/lineLocation2.png");

        color = new Color(90, 199, 35);
//        buildToolMoveDown(64, 64, color, "./src/image/toolLineDown2.png");
//        buildToolMoveBottom(64, 64, color, "./src/image/toolLineBottom2.png");
//        buildToolMoveUp(64, 64, color, "./src/image/toolLineUp2.png");
//        buildToolMoveTop(64, 64, color, "./src/image/toolLineTop2.png");
//        buildToolDelete(64, 64, color, "./src/image/toolLineDel2.png");
//        buildToolAdd(64, 64, color, "./src/image/toolLineAdd2.png");

//        color = new Color(90, 199, 35);
//        buildAddInner(color, "./src/image/addInner2.png");
//        buildDelInner(color, "./src/image/delInner2.png");
//        buildClearrepeat(color, "./src/image/clearrepeat2.png");
//        buildCategory(color, "./src/image/category2.png");
//        buildScheme(color, "./src/image/scheme2.png");
//        buildShowAdv(color, "./src/image/showAdv2.png");

        color = new Color(90, 199, 35);
//        buildClearAll(color, "./src/image/clearAll2.png");
    }

    private static final Map<String, ImageIcon> icons = new HashMap<String, ImageIcon>();

    private static final String IMAGE_PATH = "/image/";

    public static Image getImage(String filename) {
        try {
            String fullname = IMAGE_PATH + filename;
            URL url = ImageUtils.class.getResource(fullname);
            if(url != null) {
                BufferedImage bi = ImageIO.read(url);
                ImageProducer producer = bi.getSource();
                return Toolkit.getDefaultToolkit().createImage(producer);
            }

            return null;
        }
        catch (Exception e) {
            throw new RuntimeException("图片[" + filename + "]不存在。");
        }
    }

    public static ImageIcon getImageIcon(String filename) {
        if(filename == null) {
            return null;
        }

        ImageIcon icon = icons.get(filename);
        if(icon == null) {
            Image image = getImage(filename);
            if(image != null) {
                icon = new ImageIcon(image);
                icons.put(filename, icon);
            }
        }

        return icon;
    }

    private static void buildBrowser (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆点
        g2d.setPaint(color);
        float w = width/7f;
        g2d.translate(width/2f, height/2f-w/2f);
        float space = w/4f;
        //中心
        Ellipse2D.Float center = new Ellipse2D.Float(0-w/2f, 0, w, w);
        g2d.fill(center);
        //左边
        Ellipse2D.Float left = new Ellipse2D.Float(0-w/2f-space-w, 0, w, w);
        g2d.fill(left);
        //右边
        Ellipse2D.Float right = new Ellipse2D.Float(w/2f+space, 0, w, w);
        g2d.fill(right);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildMoveDown (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.45f;
        float x2 = x1;
        float y2 = y1 + h;

        y1 += 1;
        y2 += 1;

        Line2D.Float line = new Line2D.Float(x1, y1, x2, y2-2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildMoveBottom (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.45f;
        float x2 = x1;
        float y2 = y1 + h;

        Line2D.Float line = new Line2D.Float(x1, y1, x2, y2-2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y2 + 2, x1+w/2f, y2 + 2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildMoveUp (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.55f;
        float x2 = x1;
        float y2 = y1 + h;

        Line2D.Float line = new Line2D.Float(x1, y1+2, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildMoveTop (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.55f;
        float x2 = x1;
        float y2 = y1 + h;

        y1 += 1;
        y2 += 1;

        Line2D.Float line = new Line2D.Float(x1, y1+2, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 - 2, x1+w/2f, y1 - 2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildDelete (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        g2d.translate(width/2f, height/2f);
        float w = width * 0.4f;
        Line2D.Float line = new Line2D.Float(0-0.5f*w, 0, 0.5f*w, 0);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildAdd (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        g2d.translate(width/2f, height/2f);
        float w = width * 0.4f;
        Line2D.Float line = new Line2D.Float(0-0.5f*w, 0, 0.5f*w, 0);
        g2d.draw(line);
        line = new Line2D.Float(0, 0-0.5f*w+1, 0, 0.5f*w+1);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildLineLocation (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画中线
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(1.2f));
        g2d.drawOval(3, 3, width - 6, height - 6);

        g2d.translate(width/2f, height/2f);
        g2d.fillOval(-2, -2, 4, 4);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildLogo(Color color, String file) throws Exception {
        int width = 128;
        int height = 128;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

//        g2d.setColor(Color.black);
//        g2d.drawRect(0, 0, width-1, height-1);
        //画中线
        g2d.setPaint(color);
//        g2d.fillRect(0, 0, width, height);
        g2d.fillOval(3, 3, width - 6, height - 6);
        g2d.setFont(new Font("Dialog", Font.BOLD, 112));
        g2d.setColor(Color.WHITE);
        g2d.drawString("J", 32, height-22);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildAddInner(Color color, String file) throws Exception {
        int width = 128;
        int height = 128;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

//        g2d.setColor(Color.black);
//        g2d.drawRect(0, 0, width-1, height-1);
        //画中线
        g2d.setPaint(color);
//        g2d.fillRect(0, 0, width, height);
        g2d.fillOval(3, 3, width - 6, height - 6);
        g2d.setFont(new Font("Dialog", Font.BOLD, 106));
        g2d.setColor(Color.WHITE);
        g2d.drawString("in", 16, height-28);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildDelInner(Color color, String file) throws Exception {
        int width = 128;
        int height = 128;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

//        g2d.setColor(Color.black);
//        g2d.drawRect(0, 0, width-1, height-1);
        //画中线
        g2d.setPaint(color);
//        g2d.fillRect(0, 0, width, height);
        g2d.fillOval(3, 3, width - 6, height - 6);
        g2d.setFont(new Font("Dialog", Font.BOLD, 106));
        g2d.setColor(Color.WHITE);
        g2d.drawString("in", 16, height - 28);
        g2d.setStroke(new BasicStroke(4f));
        g2d.drawLine(16, 70, 112, 70);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildClearrepeat(Color color, String file) throws Exception {
        int width = 128;
        int height = 128;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

//        g2d.setColor(Color.black);
//        g2d.drawRect(0, 0, width-1, height-1);
        //画中线
        g2d.setPaint(color);
//        g2d.fillRect(0, 0, width, height);
        g2d.fillOval(3, 3, width - 6, height - 6);
        g2d.setFont(new Font("Dialog", Font.BOLD, 110));
        g2d.setColor(Color.WHITE);
        g2d.drawString("-r", 18, height-30);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildCategory(Color color, String file) throws Exception {
        int width = 32;
        int height = 32;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new Rectangle2D.Float(0, 0, width, height);
        g2d.setClip(bgRect);

        ImageIcon icom = new ImageIcon(ImageUtils.class.getResource("/image/bak/category_32.png"));
        g2d.drawImage(icom.getImage(), 0, 0, null);

        g2d.setPaint(color);
        g2d.fillOval(16, 16, 16, 16);
        g2d.setColor(Color.WHITE);
        g2d.setStroke(new BasicStroke(3f));
        g2d.drawLine(20, 23, 28, 23);
        g2d.drawLine(24, 19, 24, 27);
        ImageIO.write(image, "png", new File(file));
    }

    private static void buildScheme(Color color, String file) throws Exception {
        int width = 32;
        int height = 32;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new Rectangle2D.Float(0, 0, width, height);
        g2d.setClip(bgRect);

        ImageIcon icom = new ImageIcon(ImageUtils.class.getResource("/image/bak/scheme_32.png"));
        g2d.drawImage(icom.getImage(), 0, 0, null);

        g2d.setPaint(color);
        g2d.fillOval(16, 16, 16, 16);
        g2d.setColor(Color.WHITE);
        g2d.setStroke(new BasicStroke(3f));
        g2d.drawLine(20, 23, 28, 23);
        g2d.drawLine(24, 19, 24, 27);
        ImageIO.write(image, "png", new File(file));
    }

    private static void buildShowAdv(Color color, String file) throws Exception {
        int width = 64;
        int height = 64;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

//        g2d.setColor(Color.black);
//        g2d.drawRect(0, 0, width-1, height-1);
        //画中线
        g2d.setPaint(color);
//        g2d.fillRect(0, 0, width, height);
        g2d.fillOval(2, 2, width - 4, height - 4);
        g2d.setColor(Color.WHITE);
        g2d.setStroke(new BasicStroke(4f));
        int starty = 22;
        int dy = 11;
        int x = 16;
        int x1 = 25;
        int x2 = 47;
        g2d.drawLine(x, starty,x+2, starty);
        g2d.drawLine(x1, starty, x2, starty);
        starty += dy;
        g2d.drawLine(x, starty,x+2, starty);
        g2d.drawLine(x1, starty, x2, starty);
        starty += dy;
        g2d.drawLine(x, starty,x+2, starty);
        g2d.drawLine(x1, starty, x2, starty);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolMoveDown (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.45f;
        float x2 = x1;
        float y2 = y1 + h;

        y1 += 1;
        y2 += 1;

        Line2D.Float line = new Line2D.Float(x1, y1, x2, y2-2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolMoveBottom (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.45f;
        float x2 = x1;
        float y2 = y1 + h;

        Line2D.Float line = new Line2D.Float(x1, y1, x2, y2-2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.7f, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y2 + 2, x1+w/2f, y2 + 2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolMoveUp (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.55f;
        float x2 = x1;
        float y2 = y1 + h;

        Line2D.Float line = new Line2D.Float(x1, y1+2, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolMoveTop (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        float h = height * 0.4f;
        float w = width * 0.3f;

        float x1 = width * 0.5f;
        float y1 = (height - h) * 0.55f;
        float x2 = x1;
        float y2 = y1 + h;

        y1 += 1;
        y2 += 1;

        Line2D.Float line = new Line2D.Float(x1, y1+2, x2, y2);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);
        line = new Line2D.Float(x1+w/2f, y1 + h*0.3f, x1, y1);
        g2d.draw(line);

        line = new Line2D.Float(x1-w/2f, y1 - 2, x1+w/2f, y1 - 2);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildClearAll(Color color, String file) throws Exception {
        int width = 64;
        int height = 64;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        g2d.setFont(new Font("Dialog", Font.BOLD, 44));
        g2d.drawString("C", 15, height-15);
        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolDelete (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        g2d.translate(width/2f, height/2f);
        float w = width * 0.4f;
        Line2D.Float line = new Line2D.Float(0-0.5f*w, 0, 0.5f*w, 0);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

    private static void buildToolAdd (
            int width, int height, Color color, String file) throws Exception {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Shape bgRect = new RoundRectangle2D.Float(0, 0, width, height, width/3.0f, height/3.0f);
        g2d.setClip(bgRect);

        //画圆
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(width * 0.16f));
        g2d.drawOval(5, 5, width - 10, height - 10);

        //画中线
        g2d.setStroke(new BasicStroke(width * 0.08f));
        g2d.translate(width/2f, height/2f);
        float w = width * 0.4f;
        Line2D.Float line = new Line2D.Float(0-0.5f*w, 0, 0.5f*w, 0);
        g2d.draw(line);
        line = new Line2D.Float(0, 0-0.5f*w+1, 0, 0.5f*w+1);
        g2d.draw(line);

        g2d.dispose();

        ImageIO.write(image, "png", new File(file));
    }

}
